﻿@echo off
setlocal

REM 设置代码页为65001 (UTF-8)
chcp 65001

REM 配置程序和服务名称
set "SERVICE_NAME=LogCenterService"
set "SERVICE_DESCRIPTION=日志服务，默认端口6162"

REM 获取当前脚本所在目录
set "SCRIPT_DIR=%~dp0"

REM 查找当前目录下的唯一 exe 文件
for %%f in ("%SCRIPT_DIR%*.exe") do set "EXE_NAME=%%~nxf"

REM 检查是否找到了唯一的 exe 文件
if not defined EXE_NAME (
    echo No executable file found in %SCRIPT_DIR%
    endlocal
    pause
    exit /b 1
)

set "EXE_PATH=%SCRIPT_DIR%%EXE_NAME%"

echo Installing service with executable path: %EXE_PATH%

REM 创建服务，并设置为自动启动
sc create "%SERVICE_NAME%" binPath= "%EXE_PATH%" start= auto

REM 设置服务描述
sc description "%SERVICE_NAME%" "%SERVICE_DESCRIPTION%"

REM 启动服务
sc start "%SERVICE_NAME%"

endlocal
echo =================================
echo install success Okkkkkkk
echo =================================
pause
